package com.atguigu.gulimall.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.gulimall.product.entity.MproductEntity;
import com.atguigu.gulimall.product.service.MproductService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;


/**
 *
 *
 * @author cpc
 * @email 1728980597@qq.com
 * @date 2022-04-06 12:49:35
 */
@RestController
@RequestMapping("product/mproduct")
public class MproductController {
    @Autowired
    private MproductService mproductService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = mproductService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{productId}")
    public R info(@PathVariable("productId") Integer productId){
		MproductEntity mproduct = mproductService.getById(productId);

        return R.ok().put("mproduct", mproduct);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MproductEntity mproduct){
        //基本的漫画信息
//        MproductEntity mproductEntity = new MproductEntity();
//        mproductEntity.setCategoryId(9);
//        mproductEntity.setProductTitle("中国惊奇先生");
//        mproductEntity.setProductName("中国惊奇先生");
//        mproductEntity.setProductIntro("身怀神鬼七杀令的屌丝青年王小二，初涉职场的美女警花李雪，心地善良的痴情小狐狸……漫画每周一三五更新（手机客户端提前1天更新），动画每周二更新，感谢大家一如既往的支持，中国惊奇先生粉丝娱乐群（群号码：93277487）已满，欢迎加入中国惊奇先生粉丝娱乐二群，群号码：273942387");
//        mproductEntity.setProductPicture("public/imgs/comics/中国惊奇先生.png");
//        mproductEntity.setProductPrice(19.9);
//        mproductEntity.setProductSellingPrice(9.9);
//        mproductEntity.setProductNum(50);
//        mproductEntity.setProductSales(10);
//        mproductService.save(mproductEntity);
//        System.out.println("-----------------存储成功");
		mproductService.save(mproduct);
		//漫画图片信息

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MproductEntity mproduct){
		mproductService.updateById(mproduct);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] productIds){
		mproductService.removeByIds(Arrays.asList(productIds));
        return R.ok();
    }

}
